package com.oa.admin.controller;

import com.baomidou.mybatisplus.plugins.Page;
import com.joneying.common.web.response.Resp;
import com.oa.admin.dto.SealAddDTO;
import com.oa.admin.dto.SealUpdateDTO;
import com.oa.admin.entity.Seal;
import com.oa.admin.service.ISealService;
import com.oa.core.PageResult;
import com.oa.core.exception.BusinessException;
import com.oa.core.exception.DataIsEmptyException;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.joneying.common.annotation.CommonController;
import org.springframework.context.annotation.Description;

import java.util.List;

import org.springframework.web.bind.annotation.RestController;
import com.oa.core.BaseController;
import springfox.documentation.annotations.ApiIgnore;

/**
 * @author syb123
 * @since 2019-01-22
 */
@RestController
@RequestMapping("/seal")
@Api(description = "公章表模块")
//@ApiIgnore
public class SealController extends BaseController {

    private final ISealService sealService;

    @Autowired
    public SealController(ISealService sealService) {
        this.sealService = sealService;
    }


    @GetMapping("/list")
    @CommonController
    @Description("列表")
    @ApiOperation(value = "列表")
    public Resp list(@ApiParam("页号") @RequestParam(required = false) Integer pageNum, @ApiParam("行数") @RequestParam(required = false) Integer pageSize) throws DataIsEmptyException {
        return new Resp<>().success(sealService.findSealList(pageNum, pageSize));
    }

    /**
     * 根据Id查询
     *
     * @param id id
     * @return Resp
     */
    @GetMapping("/{id}")
    @CommonController
    @Description("获取详细信息")
    @ApiOperation(value = "根据id查询")
    public Resp findById(@ApiParam(value = "id", required = true) @PathVariable String id) throws DataIsEmptyException {
        return sealService.findSealDetailsById(id);
    }


    /**
     * 新增
     *
     * @param sealAddDTO SealAddDTO
     * @return Resp
     */
    @PostMapping("")
    @CommonController
    @Description("新增")
    @ApiOperation(value = "新增")
    public Resp add(@ApiParam(value = "公章表对象") @RequestBody(required = false) SealAddDTO sealAddDTO) throws BusinessException {
        return sealService.addSeal(getLoginUserId(), sealAddDTO);
    }

    /**
     * 根据Id修改
     *
     * @param sealUpdateDTO SealUpdateDTO
     * @return Resp
     */
    @PutMapping("")
    @CommonController
    @Description("根据id修改")
    @ApiOperation(value = "根据id修改")
    public Resp update(@ApiParam(value = "公章表对象") @RequestBody(required = false) SealUpdateDTO sealUpdateDTO) throws BusinessException {
        return sealService.updateSeal(sealUpdateDTO);
    }

    /**
     * 根据Id删除
     *
     * @param id id
     * @return Resp
     */
    @DeleteMapping("/{id}")
    @CommonController
    @Description("根据id删除")
    @ApiOperation(value = "根据id删除")
    public Resp delete(@ApiParam(value = "id", required = true) @PathVariable("id") String id) throws BusinessException {
        return sealService.deleteSeal(id);
    }
}
